/*
	inspect
*/

var util = require('util');

function testFunction(msg1, msg2) {
	return msg1 + msg2;
}

var parent = new Object();
parent.name = "parent";
parent.func = testFunction;

var child1 = new Object();
child1.name = "child1";
parent.child = child1;

var child2 = new Object();
child2.name = "child2";
child1.child = child2;

var child3 = new Object();
child3.name = "child3";
child2.child = child3;


/*console.log(util.inspect(parent));
{
	name: 'parent',
	func: [Function: testFunction],
	child: {
		name: 'child1',
		child: {
			name: 'child2',
			child: [Object]
		}
	}
}*/


/*console.log(util.inspect(parent, {showHidden: true}));
{
	name: 'parent',
	func: {
		[Function: testFunction]
		[length]: 2,
		[name]: 'testFunction',
		[arguments]: null,
		[caller]: null,
		[prototype]: {
			[constructor]: [Circular]
		}
	},
	child: {
		name: 'child1',
		child: {
			name: 'child2',
			child: [Object]
		}
	}
}*/


/*console.log(util.inspect(parent, {showHidden: true, depth: 3, colors: true}));
{
	name: 'parent',
	func: {
		[Function: testFunction]
		[length]: 2,
		[name]: 'testFunction',
		[arguments]: null,
		[caller]: null,
		[prototype]: {
			[constructor]: [Circular]
		}
	},
	child: {
		name: 'child1',
		child: {
			name: 'child2',
			child: {
				name: 'child3'
			}
		}
	}
}*/


/*util.inspect.styles.special = 'red';
console.log(util.inspect(parent, {showHidden: true, depth: 3, colors: true}));*/


/*
parent.inspect = function() {
	return this.name;
}
console.log(util.inspect(parent, {customInspect: true}));
//console.log(util.inspect(parent));  customInspect默认就是true

parent
*/



/*
child2.inspect = function() {
	// 这里customInspect必须指定为false，不然报错
	return util.inspect(this, {colors: true, customInspect: false});
}
// 这里depth随便指定哪个值，输出的结果都不变？？
console.log(util.inspect(parent, {customInspect: true, depth: 4}));
{
	name: 'parent',
	func: [Function: testFunction],
	child: {
		name: 'child1',
		child: {
			name: 'child2',
			child: {
				name: 'child3'
			},
			inspect: [Function]
		}
	}
}
*/


/*
child2.inspect = function(depth) {
	console.log(depth); 
	// 这里customInspect必须指定为false，不然报错
	// 这里depth直接写死指定为0或1，输出结果都一样
	// depth到底怎么定义的？？？
	return util.inspect(this, {depth: depth-2, customInspect: false});
}
console.log(util.inspect(parent, {customInspect: true, depth: 4}));

2
{
	name: 'parent',
	func: [Function: testFunction],
	child: {
		name: 'child1',
		child: {
			name: 'child2',
			child: [Object],
			inspect: [Function]
		}
	}
}
*/

